//	@file Version: 1.0
//	@file Name: ADP_F_fillItems.sqf
//	@file Author: THumbert
//	@file Created: 12/14/2013
//	@file Description: Fills listbox with Weapons

disableSerialization;
private ["_isWeapon","_cfgWeapons"];
_disp = _this select 0;
_control = _this select 1;
_type = _this select 2;
_display = findDisplay _disp;
_ctrl = _display displayctrl _control;
_listbox = _control;
lbClear _listbox;

if (_type != 3) then {_cfgWeapons = configFile >> "cfgWeapons";} else {_cfgWeapons = configFile >> "cfgMagazines";};
_weaponInfo = {((getNumber(_this >> "scope")==2)&&(getNumber(_this >> "access")!=0)&&(getText(_this >> "model")!="")&&(getText(_this >> "displayName")!=""))};
_nadeInfo = {((getNumber(_this >> "scope")==2)&&(getText(_this >> "model")!="")&&(getText(_this >> "displayName")!=""))};

switch (_type) do           /*0 for primary, 1 for secondary, 2 for Launchers            */
{
	case 0: {_isWeapon = {(_this call _weaponInfo)&&(getNumber(_this >> "type") in [1,5])&&(getNumber(_this >> "WeaponSlotsInfo" >> "mass")>=1)};};
	case 1: {_isWeapon = {(_this call _weaponInfo)&&(getNumber(_this >> "type") in [2,15])&&(getNumber(_this >> "WeaponSlotsInfo" >> "mass")>=1)};};
	case 2: {_isWeapon = {(_this call _weaponInfo)&&(getNumber(_this >> "type") in [4,15])&&(getNumber(_this >> "WeaponSlotsInfo" >> "mass")>=1)};};
	case 3: {ListContents = "Grenade";_isWeapon = {(_this call _nadeInfo)&&(getNumber(_this >> "mass")>=4)&&(getNumber(_this >> "count")==1)&&(getNumber(_this >> "type") in [256,16])};};
};	
hint "Adding Weapons";
for "_i" from 0 to (count _cfgweapons)-1 do {
			_weapon = _cfgweapons select _i;
			if (isClass _weapon) then {
				if (_weapon call _isWeapon) then {
					_index = lbAdd [_listbox, getText(_weapon >> "displayName")];
					lbSetData [_listbox, _index,configName _weapon];
					lbSetPicture [_listbox, _index,getText(_weapon >> "picture")];	
					lbSetValue [_listbox, _index,_type];
				};
			};
};
lbSort _CTRL;		
